
import LXCOM from '../../common/common.js'
import {LGXEnums}  from '../../common/sysenum.js'

import AbsControler from '../abscontroler.js'
import modify from './singlemodifycontroler.js'
import multiModify from './multimodifycontroler.js'
import pickpointcontroler from './pickpointcontroler.js';

class ModifyMainControler extends AbsControler.AbsControler {
    constructor(parent, datamanger, mulselsvc) {
        super(datamanger);
        this.m_preLMosDwnPt = new LXCOM.LGXPoint();
        this.m_preLMosUpPt = new LXCOM.LGXPoint();
        this.multiControler = new multiModify.MultiModifyControler(this, datamanger, mulselsvc);
        this.singleModifyControler = new modify.SingleModifyControler(datamanger);
        this.pickPointControler = new pickpointcontroler.PickPointControler(datamanger);
        this.m_preSelGraph = false;
        this.parent = parent;
    }

    act2Mouse(mosEvnt, worldPos) {
        this.dataManger.clearFreshZone();
        this.m_preLMosDwnPt.clone(worldPos);
        let resultState = this.act2MultiStepSubEditMode(mosEvnt, worldPos);
        if (!resultState){
            if (mosEvnt.type == LGXEnums.LGXMouseMode.LMouseDown) {
                resultState = this.act2LMosDown(mosEvnt, worldPos);
            }
            else if (mosEvnt.type == LGXEnums.LGXMouseMode.LMouseUp) {
                this.m_preLMosUpPt.clone(worldPos);
                resultState = this.act2LMosUp(mosEvnt, worldPos);
            }
            else if (mosEvnt.type == LGXEnums.LGXMouseMode.LMouseDbClick) {
                resultState = this.act2DBClick(mosEvnt, worldPos);
            }
            else if (mosEvnt.type == LGXEnums.LGXMouseMode.mouseMove) {
                resultState = this.act2MouseMove(mosEvnt, worldPos);
            }
            else if (mosEvnt.type == LGXEnums.LGXMouseMode.mouseDrag) {
                resultState = this.act2LMouseDrag(mosEvnt, worldPos);
            }
            this.m_preLMosDwnPt.clone(worldPos);
        }
        
        return resultState;
    }

    act2LMosDown(mosEvnt, tpoint) {
        var haveSelectGraph = false;
        if (this.dataManger.getMultiModifyMode()) {
            this.multiControler.act2Mouse(mosEvnt, tpoint);
        }
        else {
            this.singleModifyControler.act2Mouse(mosEvnt, tpoint);
            if (this.dataManger.getCurentGraph()) {
                haveSelectGraph = true;
            }
            if (!haveSelectGraph) {
                this.dataManger.setMultiModifyMode(true);
                this.multiControler.act2Mouse(mosEvnt, tpoint);
            }
        }
        this.m_preSelGraph = haveSelectGraph;
        return 0;
    }

    act2LMosUp(mosEvnt, tpoint) {
        var result = 0;
        if (this.dataManger.getMultiModifyMode()) {
            result = this.multiControler.act2Mouse(mosEvnt, tpoint);
        }
        else {
            result = this.singleModifyControler.act2Mouse(mosEvnt, tpoint);
        }
        var pCurentGraph = this.dataManger.getCurentGraph();
        if (pCurentGraph) {
            // pCurentGraph.setDisplayInfoFlag(false);
        }
        return result;
    }


    act2LMouseDrag(mosEvnt, tpoint) {
        if (!this.m_preSelGraph && (this.dataManger.getMultiModifyMode())) {
            this.multiControler.act2Mouse(mosEvnt, tpoint);
        }
        else {
            this.singleModifyControler.act2Mouse(mosEvnt, tpoint);
        }
        return 0;
    }

    act2DBClick(mosEvnt, tpoint) {
        if (this.dataManger.getMultiModifyMode()) {
            this.multiControler.act2Mouse(mosEvnt, tpoint);
        }
        else {
            this.singleModifyControler.act2Mouse(mosEvnt, tpoint);
        }
        return 0;
    }

    act2MouseMove(mosEvnt, tpoint) {
        if (this.dataManger.getMultiModifyMode()) {
            this.multiControler.act2Mouse(mosEvnt, tpoint);
        }
        else {
            this.singleModifyControler.act2Mouse(mosEvnt, tpoint);
        }
        return 0;
    }

    act2MultiStepSubEditMode(mosEvnt, tpoint) {
        let controler = this.getSubControler();
        if (!controler) {
            return null;
        }
        let resultState = controler.act2Mouse(mosEvnt, tpoint);
        return resultState;
    }

    getSubControler() {
        let workMode = this.dataManger.getMapWorkMode();
        let controler = null;
        if (workMode == LGXEnums.LGXWorkMode.PickPointMode) {
            controler = this.pickPointControler;
        }
        return controler;
    }

    getparentControler() {
        return this.parent;
    }

    finishMultiMode(){
        this.multiControler.finishMultiMode();
    }
}

export default { ModifyMainControler }

